package queue_stack;


import java.util.Stack;

/**
 * 有效的括号
 *
 * https://leetcode.cn/problems/valid-parentheses/?envType=study-plan-v2&envId=top-interview-150
 */
public class ValidParentheses {

    public boolean isValid(String s) {


        Stack<Integer> data=new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char c=s.charAt(i);
            if ('{'==c){
                data.push((int) '}');
            }else if('['==c){
                data.push((int) ']');
            }else if('('==c){
                data.push((int) ')');
            }else{
                if (!data.isEmpty()||data.pop()!=c){
                    return false;
                }
            }
        }

        return  data.isEmpty();
    }
}
